import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/text_ex.dart';
import 'package:flutter_eve_plugin/constants/constant.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/constants/plot_trigger.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/fight_succ.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/share_info.dart';
import 'package:flutter_eve_plugin/pages/main/actions.dart';
import 'package:flutter_eve_plugin/plugin/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/checkpoint/main.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class CheckpointSuccFooterWidget extends StatelessWidget {
  final FightSucc info;
  final String stageId;

  const CheckpointSuccFooterWidget({Key key, this.info, this.stageId})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(
          state: store.state,
          yeXiuStateViewModel: YeXiuStateViewModel(checkpointStateViewModel:
              CheckpointStateViewModel(successFunc: () {
            store.dispatch(doTriggerPlot(PlotTrigger.plotTriggerType2, stageId,
                callback: () {
              //结束了剧情触发
              if (Navigator.canPop(context)) {
                Navigator.pop(context);
              }
            }));
          })));
    }, builder: (context, vm) {
      return Container(
        padding: EdgeInsets.only(
            left: setRatio(18), right: setRatio(18), top: setRatio(571)),
        child: Row(
          mainAxisAlignment: (info?.gradeScore?.grade ?? 0) < 30
              ? MainAxisAlignment.center
              : MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              onTap: () {
                vm.yeXiuStateViewModel.checkpointStateViewModel.successFunc();
              },
              child: Container(
                width: setRatio(160),
                height: setRatio(47),
                decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage(imageUtilYeXiu(
                            'checkpoint/icon_dialog_btn_enavailable@3x')))),
                child: Center(
                  child: TextEx(
                    '确定',
                    shadow: Color(0xCC88888B),
                    style: TextStyle(
                        decoration: TextDecoration.none,
                        color: Color(0xFFFFFFFF),
                        fontFamily: FontFamily.PINGFANG,
                        fontWeight: FontWeightCustom.PF_Medium,
                        fontSize: setTextSp(17)),
                  ),
                ),
              ),
            ),
            (info?.gradeScore?.grade ?? 0) < 30
                ? Container()
                : GestureDetector(
                    onTap: () {
                      showShareDialog(context);
                    },
                    child: Container(
                      width: setRatio(160),
                      height: setRatio(47),
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image: AssetImage(imageUtilYeXiu(
                                  'checkpoint/icon_dialog_btn_available@3x')))),
                      child: Center(
                        child: TextEx(
                          '炫耀一下',
                          shadow: Color(0xCCCB8829),
                          style: TextStyle(
                              decoration: TextDecoration.none,
                              color: Color(0xFFFFFFFF),
                              fontFamily: FontFamily.PINGFANG,
                              fontWeight: FontWeightCustom.PF_Medium,
                              fontSize: setTextSp(17)),
                        ),
                      ),
                    ),
                  )
          ],
        ),
      );
    });
  }

  showShareDialog(context) {
    List<Widget> list = List<Widget>.generate(5, (index) {
      var name = '';
      switch (index) {
        case 0:
          name = '微信好友';
          break;
        case 1:
          name = '朋友圈';
          break;
        case 2:
          name = 'QQ好友';
          break;
        case 3:
          name = 'QQ空间';
          break;
        case 4:
          name = '新浪微博';
          break;
      }
      return GestureDetector(
        onTap: () {
          if (Navigator.canPop(context)) {
            Navigator.pop(context);
          }
          var info = ShareInfo(title: '分享标题',desc: "内容。。。",platform: "WEIXIN",shareType: 4,icon: "",image: "",url: "http://www.baidu.com");
          PluginEve.sendMessage(PluginConstant.actionAppShareInfo, param: info);
        },
        child: Column(
          children: <Widget>[
            Image.asset(
              imageUtilYeXiu(
                  'checkpoint/icon_checkpoint_succ_share_${index + 1}@3x'),
              width: setRatio(59),
              height: setRatio(50),
            ),
            SizedBox(
              height: setRatio(2),
            ),
            Text(
              name,
              style: TextStyle(
                  decoration: TextDecoration.none,
                  color: Color(0xFFFFFFFF),
                  fontFamily: FontFamily.PINGFANG,
                  fontWeight: FontWeightCustom.PF_Medium,
                  fontSize: setTextSp(12)),
            )
          ],
        ),
      );
    }).toList();
    showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return Container(
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
            color: Colors.transparent,
            child: Column(
              children: <Widget>[
                Expanded(
                  child: Container(),
                ),
                Container(
                  width: setRatio(375),
                  height: setRatio(158),
                  decoration: BoxDecoration(
                      gradient: LinearGradient(colors: [
                    Color(0xFF4C4F5D),
                    Color(0xFF757C90),
                  ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: EdgeInsets.only(
                            left: setRatio(15),
                            right: setRatio(15),
                            top: setRatio(17),
                            bottom: setRatio(24)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: list,
                        ),
                      ),
                      Container(
                        width: setRatio(375),
                        height: setRatio(1),
                        color: Color(0x3FF2F2F2),
                      ),
                      GestureDetector(
                        onTap: () {
                          if (Navigator.canPop(context)) {
                            Navigator.pop(context);
                          }
                        },
                        child: Container(
                          height: setRatio(45),
                          width: setRatio(375),
                          color: Colors.transparent,
                          child: Center(
                            child: Text(
                              '取消',
                              style: TextStyle(
                                  decoration: TextDecoration.none,
                                  color: Color(0xFFFFFFFF),
                                  fontFamily: FontFamily.PINGFANG,
                                  fontWeight: FontWeightCustom.PF_Medium,
                                  fontSize: setTextSp(15)),
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                )
              ],
            ),
          );
        });
  }
}
